/**   
 * @Title: StringTools.java 
 * @Package orz.tools.projecttools 
 * @Description: TODO
 * @author Mr.Zhang   
 * @date 2017年4月26日 下午2:49:43 
 * @version V1.0   
 */
package com.agent.tool;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/** 
 * @ClassName: StringTools 
 * @Description: TODO
 * @author Mr.Zhang 
 * @date 2017年4月26日 下午2:49:43 
 *  
 */
public class StringTools {
	public static final int normalType = 0;
	public static final int positiveType = 1;
	public static final int[] type = {
		normalType,
		positiveType
	};
	public static final ArrayList<String> strList = new ArrayList<String>();
	static {
		strList.add(normalType, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
		strList.add(positiveType, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
	}
	public static boolean hasThisType(int payType){
		for(int tmpPayType : type){
			if(tmpPayType == payType){
				return true;
			}
		}
		return false;
	}
	public static String getRandomString(int length,int stringType) {
	    //随机字符串的随机字符库
	    StringBuffer sb = new StringBuffer();
	    String KeyString = strList.get(stringType);
	    if(!hasThisType(stringType)) {
	    	return null;
	    }
	    int len = KeyString.length();
	    for (int i = 0; i < length; i++) {
	       sb.append(KeyString.charAt((int) Math.round(Math.random() * (len - 1))));
	    }
	    return sb.toString();
	}
	public static String getRandomString(int length) {
	    //随机字符串的随机字符库
	    StringBuffer sb = new StringBuffer();
	    String KeyString = strList.get(normalType);
	    int len = KeyString.length();
	    for (int i = 0; i < length; i++) {
	       sb.append(KeyString.charAt((int) Math.round(Math.random() * (len - 1))));
	    }
	    return sb.toString();
	}
}
